package com.wangy.database.jdbc;


import java.beans.PropertyVetoException;

import org.apache.commons.dbcp.BasicDataSource;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import com.wangy.database.bean.JdbcInfo;

public class DatasourceFactory {
	
	public static BasicDataSource getBasicDataSource(JdbcInfo jdbcInfo){
		BasicDataSource dataSource = new BasicDataSource();
		dataSource.setDriverClassName(jdbcInfo.getDriverName());
		dataSource.setUrl(jdbcInfo.getUrl());
		dataSource.setUsername(jdbcInfo.getUsername());
		dataSource.setPassword(jdbcInfo.getPassword());
		return dataSource;
	}
	
	public static ComboPooledDataSource getComboPooledDataSource(JdbcInfo jdbcInfo){
		ComboPooledDataSource dataSource = new ComboPooledDataSource();
		try {
			dataSource.setDriverClass(jdbcInfo.getDriverName());
			dataSource.setJdbcUrl(jdbcInfo.getUrl());
			dataSource.setUser(jdbcInfo.getUsername());
			dataSource.setPassword(jdbcInfo.getPassword());
		} catch (PropertyVetoException e) {
			e.printStackTrace();
		}
	
		return dataSource;
	}
	

}
